#######################################################
# ETFDAQ Project
#
# Author SUN Yazhou
# Created: 2024/08/11
# Last modified: 2024/08/11
#######################################################

cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)

find_program(CLANG_EXECUTABLE clang++)
find_program(GXX_EXECUTABLE g++)
if(CLANG_EXECUTABLE)
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_C_COMPILER "clang")
elseif(GXX_EXECUTABLE)
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_C_COMPILER "gcc")
else()
message(FATAL_ERROR "No CXX compilers were found")
endif()

project(ETFDAQ VERSION 1.0.0)

set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# Build Type: MinSizeRel Debug Release RelWithDebInfo
# set(BUILD_TYPE Debug) # appropriate for DEBUG, yet rather slow
set(BUILD_TYPE Release) # compiler-optimized, extreme performance
# set(BUILD_TYPE MinSizeRel) # rel, and with minized lib and exe size
# set(BUILD_TYPE RelWithDebInfo) # rel, and with DEB info
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE ${BUILD_TYPE})
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

link_libraries(yaml-cpp rt)
add_subdirectory(sis) # interface for sis3100 controlers
add_subdirectory(vmedaq) # high level calls
add_subdirectory(gui) # the Qt GUI library
add_subdirectory(src) # the user applications

file(COPY ${CMAKE_SOURCE_DIR}/config/sh/cmc_update.sh DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/config/sh/mi_update.sh DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/config/sh/ol_update.sh DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/config/sh/i7_update.sh DESTINATION ${CMAKE_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/config/sh/slim_update.sh DESTINATION ${CMAKE_BINARY_DIR})

# print the build type
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UPPER)
execute_process(
  COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
  OUTPUT_VARIABLE COMPILER_VERSION
)
string(STRIP ${COMPILER_VERSION} COMPILER_VERSION_STRIPPED)
message(STATUS "======= BUILD TYPE ===========")
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER} ${COMPILER_VERSION_STRIPPED}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}   ${CMAKE_CXX_FLAGS_${BUILD_TYPE_UPPER}}")
message(STATUS "(TIPS: Change with -DCMAKE_BUILD_TYPE=<build_type>)")
message(STATUS "(TIPS: Available build_type-s: MinSizeRel Debug Release RelWithDebInfo)")
message(STATUS "======= BUILD TYPE ===========")
